﻿namespace LeetCodeProject._0001_1000._001_100._71_80._075;

public class Solution
{
    public void SortColors(int[] nums)
    {
        int i = 0, left = 0;
        int right = nums.Length - 1;
        while (i <= right)
        {
            int v = nums[i];
            if (v == 0)
            {
                Swap(nums, i++, left++);
            }
            else if (v == 1)
            {
                i++;
            }
            else
            {
                Swap(nums, i, right--);
            }
        }
    }

    private void Swap(int[] arr, int i, int j)
    {
        int tmp = arr[i];
        arr[i] = arr[j];
        arr[j] = tmp;
    }
}